package com.xhsj.user.hr.base;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author suxl
 * @date 2018年9月30日 下午3:47:48
 * @TableField(exist = false),表示排除类中的属性.
 */
@Data
public abstract class BaseEntity<T extends Model> extends Model<T> {
    //	@TableField(exist = false)
    @JsonIgnore
    protected static int currentPage;
    //	@TableField(exist = false)
    @JsonIgnore
    protected static int pageSize;

    //排序列表
    @JsonIgnore
    @TableField(exist = false)
    private List<Map<String,String>> orderBy = Lists.newArrayList();

    /**
     * 自增id
     */
    @TableField("id")
    @TableId(type = IdType.AUTO)
    protected Long id;

    /**
     * 创建人
     */
    @TableField("create_by")
    protected Long createBy;

    /**
     * 创建人姓名
     */
//    @TableField("create_name")
//    protected String createName;
    /**
     * 创建时间
     */
    @TableField("create_date")
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    protected Date createDate;
    /**
     * 修改人
     */
    @TableField("update_by")
    protected Long updateBy;

    /**
     * 修改人姓名
     */
//    @TableField("update_name")
//    protected String updateName;
    /**
     * 修改时间
     */
    @TableField("update_date")
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    protected Date updateDate;
    /**
     * 删除标记
     */
    @TableField(value = "del_flag")
    @TableLogic //表字段逻辑处理注解（逻辑删除）
    protected int delFlag = 0;
    /**
     * 备注
     */
    @TableField("remarks")
    protected String remarks;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BaseEntity<?> that = (BaseEntity<?>) o;
        return delFlag == that.delFlag &&
                Objects.equals(orderBy, that.orderBy) &&
                Objects.equals(id, that.id) &&
                Objects.equals(createBy, that.createBy) &&
                Objects.equals(createDate, that.createDate) &&
                Objects.equals(updateBy, that.updateBy) &&
                Objects.equals(updateDate, that.updateDate) &&
                Objects.equals(remarks, that.remarks);
    }

    @Override
    public int hashCode() {
        return Objects.hash(orderBy, id, createBy, createDate, updateBy, updateDate, delFlag, remarks);
    }
}
